package com.sright.bcard.mini.web.controller;

import com.sright.bcard.common.service.share.dto.request.MiniLoginRequest;
import com.sright.bcard.mini.web.constant.WebUrl;
import com.sright.bcard.user.share.request.TokenParam;
import com.sright.bcard.user.share.request.WxappLoginParam;
import com.sright.bcard.user.share.service.LoginService;
import com.sright.common.response.SrightResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping(value = WebUrl.Login)
    public SrightResponse login(@RequestBody MiniLoginRequest miniLoginRequest) {
        return loginService.login(miniLoginRequest.getCode());
    }

    @PostMapping(value = WebUrl.SetUserInfo)
    public SrightResponse setUserInfo(@RequestBody WxappLoginParam param, @RequestAttribute TokenParam tokenParam) throws Exception {
        loginService.setUserInfo(param,tokenParam);
        return SrightResponse.defaultSuccess();
    }

    @GetMapping(value = WebUrl.TestLogin)
    public SrightResponse testLogin() {
        return loginService.testLogin();
    }

    @GetMapping(value = WebUrl.ShowTestButton)
    public SrightResponse showButton(@RequestParam String version) {
        return loginService.showButton(version);
    }
}
